package com.hjh.shirodemo.service.Impl;

import com.hjh.shirodemo.entity.UserBean;
import com.hjh.shirodemo.repository.UserBeanRepository;
import com.hjh.shirodemo.service.IUserService;
import org.apache.catalina.User;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
//配置缓存
//@CacheConfig(cacheNames = "IUserService")
public class IUserServiceImpl implements IUserService {

    @Resource
    private UserBeanRepository userBeanRepository;

//    //配置缓存
//    @Cacheable(value = "getSysUserListBiz",keyGenerator = "keyGenerator")
    @Override
    public UserBean getUser(String usrName) {
        return userBeanRepository.findUserByUsrName(usrName);
    }

    @Override
    public UserBean login(String usrName, String userPassword) {
        List<UserBean> list = userBeanRepository.findUserByUsrNameAndUsrPassword(usrName,userPassword);
        if (list!=null && list.size()>0){
            list.get(0).getRole().getRoleName();
            return list.get(0);
        }
        return null;
    }
//
//    @Override
//    public User addUser(User user) {
//        return null;
//    }
//
//    @Override
//    public void deleteUser(Long usrId) {
//
//    }
//
//    @Override
//    public User updateUser(User user) {
//        return null;
//    }
//
//    @Override
//    public User getUser(Long usrId) {
//        return userRepository.getOne(usrId);
//    }
//
//    @Override
//    public List<User> findAllUsers() {
//        return userRepository.findAll();
//    }
}
